package com.example.q_kang.hhh.setting;

import com.hjq.toast.ToastUtils;
import com.lzy.okgo.model.Response;
import com.sskj.base.BasePresenter;
import com.sskj.base.api.Constant;
import com.sskj.base.base.HttpData;
import com.sskj.base.bean.BankTypes;
import com.example.q_kang.hhh.api.JsonCallBack;

import java.util.List;


/**
 * @author Hey
 * Create at  2019/04/10
 */
class SetBankPresenter extends BasePresenter<SetBankActivity> {

    public void getAddBankList() {
        httpService.getAddBankList()
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<BankTypes>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<BankTypes>>> response) {
                        HttpData<List<BankTypes>> body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.showBnaks(body.getData());
                        }

                    }
                });
    }

    public void sendCode(String mobile) {
        httpService.getCode(mobile)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtils.show(httpData.getMsg());
                        if (httpData.getStatus() == Constant.OK) {
                            mView.sendCodeSuccess();
                        }
                    }
                });
    }

    public void bindBank(String bank_name, String bank_account, String bankId, String bank_address, String mobileCode) {
        httpService.bindBank(bank_name, bank_account, bankId, bank_address, mobileCode)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());
                        if (body.getStatus() == Constant.OK) {
                            mView.finish();
                        }
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }

    public void editBank(String bank_name, String bank_account, String bankId, String bank_address, String mobileCode, String mobile) {
        httpService.editBank(bank_name, bank_account, bankId, bank_address, mobileCode, mobile)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());
                        if (body.getStatus() == Constant.OK) {
                            mView.finish();
                        }
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }
}
